<?php
class EventPrivilagesController extends AppController {

	var $name = 'EventPrivilages';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->EventPrivilage->recursive = 0;
		$this->set('eventPrivilages', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid event privilage', true));
			$this->redirect(array('action' => 'index'));
		}
		$privilages = $this->EventPrivilage->find('first', array(
										'conditions' => array(
											'EventPrivilage.id' => $id
										),
										'recursive' => -1
									)
								);
		if(!$privilages){
			$this->Session->setFlash(__('Invalid event privilage',true));
			$this->redirect(array('controller'=>HOME_CONTROLLER,'index'=>'index'));
		}
		$this->set('eventPrivilage', $privilages);
	}

	function add() {
		if (!empty($this->data)) {
			$this->EventPrivilage->create();
			if ($this->EventPrivilage->save($this->data)) {
				$this->Session->setFlash(__('The EventPrivilage has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The EventPrivilage could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid EventPrivilage', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->EventPrivilage->save($this->data)) {
				$this->Session->setFlash(__('The EventPrivilage has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The EventPrivilage could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$privilage = $this->EventPrivilage->read(null, $id);
			if(!$privilage){
				$this->Session->setFlash(__('Invalid event privilage',true));
				$this->redirect(array('controller'=>HOME_CONTROLLER,'index'=>'index'));
			}
			$this->data = $this->EventPrivilage->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for EventPrivilage', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->EventPrivilage->del($id)) {
			$this->Session->setFlash(__('EventPrivilage deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The EventPrivilage could not be deleted. Please, try again.', true));
		$this->redirect(array('controller'=>HOME_CONTROLLER,'action' => 'index'));
	}

}
?>